/**
 * OWASP GoatDroid Project
 * 
 * This file is part of the Open Web Application Security Project (OWASP)
 * GoatDroid project. For details, please see
 * https://www.owasp.org/index.php/Projects/OWASP_GoatDroid_Project
 *
 * Copyright (c) 2011 - The OWASP Foundation
 * 
 * GoatDroid is published by OWASP under the GPLv3 license. You should read and accept the
 * LICENSE before you use, modify, and/or redistribute this software.
 * 
 * @author Jack Mannino, nVisium Security (https://www.nvisiumsecurity.com)
 * @created 2011
 */
package org.owasp.goatdroid.fourgoats.webservice.badges;

import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

import org.owasp.goatdroid.fourgoats.webservice.base.BaseDAO;
import com.mysql.jdbc.Connection;

public class BadgesDAO extends BaseDAO {

	public BadgesDAO() throws InstantiationException, IllegalAccessException,
			ClassNotFoundException, SQLException {
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		conn = (Connection) DriverManager
				.getConnection("Constants.DB_CONNECTION_STRING)");
	}

	public HashMap<String, String> getBadgesForVenue(String venueID)
			throws SQLException {

		String sql = "select badges.badgeName, badges.badgeDescription, rewards.rewardName, "
				+ "rewards.totalCheckinsRequired from badges inner join rewards on "
				+ "badges.rewardID = rewards.rewardID where badges.venueID = ?";
		PreparedStatement selectStatement = (PreparedStatement) conn
				.prepareCall(sql);
		selectStatement.setString(1, venueID);
		ResultSet rs = selectStatement.executeQuery();
		HashMap<String, String> badges = new HashMap<String, String>();
		int count = 0;
		while (rs.next()) {
			badges.put("badgeName" + count, rs.getString("badgeName"));
			badges.put("badgeDescription" + count,
					rs.getString("badgeDescription"));
			badges.put("rewardRequiredID" + count,
					rs.getString("rewardRequiredID"));
			badges.put("totalCheckinsRequired" + count,
					Integer.toString(rs.getInt("totalCheckinsRequired")));
			count++;
		}
		return badges;
	}

}
